//
//  WZBackTitleViewController.swift
//  weiBo---01
//
//  Created by 王—wagn on 16/4/11.
//  Copyright © 2016年 王—wagn. All rights reserved.
//

import UIKit

class WZBackTitleViewController: UINavigationController,UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        //导航栏的图片
        navigationBar.setBackgroundImage(UIImage(named: "navbarbackimaeg"), forBarMetrics: .Default)
        self.interactivePopGestureRecognizer?.delegate = self
       
    }
    
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        //设置viewController 的navgitem.left
        //获取控制器的title
        if childViewControllers.count > 0 {
        
            var backtitle = "返回"
            if childViewControllers.count == 1 {
                
                backtitle = childViewControllers.first?.title ?? ""
            }
        
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(imageName: "navigationbar_back_withtext", title: backtitle, target: self, action: "backBtnView")
            //工具栏
            navigationController?.hidesBottomBarWhenPushed = true
            viewController.view.backgroundColor = UIColor.whiteColor()
            
        }
         super.pushViewController(viewController, animated: animated)
        
        print(childViewControllers.count)

    }

    //返回
    @objc private func backBtnView() {
    
        self.popViewControllerAnimated(true)
    
    }
    
    //手势代理设置
    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
        
        return childViewControllers.count != 1
    }
  
    
}
